﻿using System.Windows.Forms;
using GeoSketch2.Core;

namespace GeoSketch2.Archaeo
{
    /// <summary>
    /// A tool to add text on a sketch
    /// Click the location, then enter the text to be displayed
    /// </summary>
    public class TInputText: BaseArchaeoTool
    {
        InputText InputText;

        #region Constructor
        /// <summary>
        /// The tool to display a text
        /// </summary>
        /// <param name="Viewport">The viewport to draw to</param>
        public TInputText(Viewport Viewport)
            : base(Viewport,"Text")
        {
        } 
        #endregion

        #region Inputs
        /// <summary>
        /// The method called when the mouse button is down
        /// </summary>
        public override void MouseDown(MouseEventArgs MouseArgs)
        {
            ExternalPointSent(Viewport.Object2ImageTransformation.InverseTransform(MouseArgs.Location));
        }

        /// <summary>
        /// The method called when a text is sent to the tool
        /// </summary>
        public override void TextEntry(string Text)
        {
            if (InputText == null)
            {
                ExternalPointSent(GetCoordinatesFromString(Text));
            }
            else
            {
                InputText.Text = Text;
                Viewport.GeoObjects.Add(InputText);
                InputText = null;
                RefreshViewport();
                SendMessage("Click the location of the text");
            }
        }

        /// <summary>
        /// The method called when a point in object coordinates is sent to the tool
        /// </summary>
        public override void ExternalPointSent(Point2D64D Point)
        {
            InputText = new InputText(Point, "", Viewport.CurrentLayer, Viewport.CurrentExcavationArea,Viewport.CurrentColor);
            SendMessage("Enter text, then validate");
            ShowTextInput();
        }
        #endregion

        #region Region
        /// <summary>
        /// The method to be used to send the first message to the user, just after beeing selected
        /// </summary>
        public override void SendFirstMessage()
        {
            SendMessage("Click the location of the text");
        } 
        #endregion
    }
}